package com.object;
import java.util.ArrayList;
import java.util.Scanner;
public class ItemOrder {
    private String id;
    private String time;


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public ArrayList<Item> getItems() {
        return items;
    }

    public void setItems(ArrayList<Item> items) {
        this.items = items;
    }

    ArrayList<Item>items = new ArrayList<>();
    public User addOrder(User user, Scanner scanner,String id){
        //id为要加入订单的id,在购物车里
        ItemOrder itemOrder = new ItemOrder();
        for (Item itemCart : user.getItemCarts()) {
            if(itemCart.getId().equals(id)){
                itemOrder.setId(user.newUid(8));
                itemOrder.setTime(user.getTime());
                itemOrder.getItems().add(0,itemCart);
            }
        }
        user.getItemOrders().add(itemOrder);
        System.out.println("是否继续添加?  1:是    其他:否...");
        if(scanner.next().equals("1")){
            System.out.println("输入id");
            String conId = scanner.next();
            conAddOrder(user,scanner,conId);
        }
        return new User();
    }
    public User conAddOrder(User user, Scanner scanner,String id){

        for (Item itemCart : user.getItemCarts()) {
            if(itemCart.getId().equals(id)){
                user.getItemOrders().get(0).getItems().add(itemCart);
            }
        }
        System.out.println("是否继续添加?  1:是    其他:否...");
        if(scanner.next().equals("1")){
            System.out.println("输入id");
            String conId = scanner.next();
            conAddOrder(user,scanner,conId);
        }
        return user;
    }
    public void viewItemOrder(User user,Scanner scanner){
        for (ItemOrder itemOrder : user.getItemOrders()) {
            System.out.println("订单编号"+itemOrder.getId()+"\n" +
                    "订单创建时间"+itemOrder.getTime());
        }
        opItemOrder(user,scanner);
    }
    public User opItemOrder(User user,Scanner scanner){
        System.out.println("请选择要查看详情的订单编号");
        String id = scanner.next();
        for (ItemOrder itemOrder : user.getItemOrders()) {
            if(itemOrder.getId().equals(id)){
                for (Item item : itemOrder.getItems()) {
                    System.out.println(item.getId()+"   "+item.getName()+"   "+item.getFactory()
                            +"    "+item.getPrice()+"    "+item.getStock()+"    "+item.getType());
                }
            }
        }

        return user;
    }
}
